<template>
  <div>
<h2>管理员登录</h2>
<table border="1">
  <tr>
    <td>用户名</td>
    <td>
      <input type="text" v-model="state.name">
    </td>
  </tr>
  <tr>
    <td>密码</td>
    <td>
      <input type="password"  v-model="state.pwd">
    </td>
  </tr>
  <tr>
    <td></td>
    <td>
      <input type="button" @click="login" value="登录">
    </td>
  </tr>
</table>
  </div>
</template>

<script setup lang="ts">
import { reactive,toRefs,onMounted } from 'vue';
import axios from 'axios';
import { useRoute,useRouter } from 'vue-router';
let route=useRoute();
let router=useRouter();
let data=reactive({
 state:{
  name:'',
  pwd:''
 }
})

let{state}=toRefs(data)
function login()
{
  let obj={
    "name":state.value.name,
    "pwd":state.value.pwd
  }
  axios({
    url:'/api/MenDian/Login',
    method:'get',
    params:obj
  })
  .then(res=>{
    if(res.data.data=="admin")
  {
    alert("登录成功")
   router.push("../madd")
  }
  if(res.data.data!="admin")
  {
    alert("登录成功")
    router.push("../pshow")
  }
  else
  {
    alert("登录失败")
  }
  })
  .catch(err=>{

  })
}
</script>

<style scoped>

</style>